package com.vhall.component.dao.interactive;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vhall.component.entity.interactive.entity.QuestionsEntity;
import com.vhall.component.entity.interactive.vo.QuestionAdmRspVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * @author guoxin.wang
 * @date 2021-05-11
 */
@Mapper
@Repository
public interface QuestionsMapper extends BaseMapper<QuestionsEntity> {

    /**
     * 根据questionId查询问卷信息。
     *
     * @param questionId 参数
     * @return 返回值
     */
    QuestionsEntity selectByQuestionId(Integer questionId);

    /**
     * 查询问卷数（admin）
     *
     * @param queryWrapper 查询条件
     * @return 房间数
     */
    @Select("select count(*) from questions left join account on questions.account_id = account.account_id ${ew.customSqlSegment}")
    Integer countQuestionForAdmin(@Param(Constants.WRAPPER) Wrapper<Object> queryWrapper);

    /**
     * 查询问卷列表（admin）
     *
     * @param page         分页参数
     * @param queryWrapper 查询条件
     * @return 问卷列表
     */
    @Select("select questions.question_id, questions.title, questions.updated_at, account.nickname "
            + "from questions left join account on questions.account_id = account.account_id ${ew.customSqlSegment}")
    Page<QuestionAdmRspVO> listQuestionForAdmin(Page<QuestionAdmRspVO> page,
                                                @Param(Constants.WRAPPER) Wrapper<QuestionAdmRspVO> queryWrapper);

}
